<template lang="pug">
  .container.homework__main
    .row
      .col-sm-3
        h2.side__menu__title 课本
        h3.side__menu__dt 高二课本
        ul.side__menu__list
          li
            a(href="") 第11章   坐标平面有理数函数
            ul
              li
                a(href="") 二次函数
              li
                a(href="") 不等式方式
                ul
                  li
                    a(href="") 坐标平面有理数函数
      .col-sm-9
        .homework__detail__desc
          span.total 共 35 道题
          .content 
            span 作业说明:  
            p {{info.name}}
        .homework__detail__item(v-for="item in list")
          .homework__detail__item__hd 1题（{{item.type | type}}）
          .homework__detail__item__bd
            p {{item.title}}
            ol
              li(v-for="option in item.options") {{option.optionName}}
          .homework__detail__item__ft
            .homework__detail__item__score 分值
              span 4
            ul.question__options
              li(v-for="option in item.options")
                label
                  input(type="checkbox")
                  | {{option.optionName}}
        button.btn.btn-outline-primary.homework__detail__submit(type="button", @click="submit") 提交    
</template>
<style lang="scss">
.homework__detail__desc {
  padding: 14px 20px;
  font-size: 12px;
  background: #fafafa;
  border-radius: 10px;
  .total {
    float: right;
    margin-left: 50px;
  }
  .content {
    display: table;
    p {
      margin: 0;
    }
    span {
      display: table-cell;
      width: 1%;
      white-space: nowrap;
      padding-right: 3px;
    }
  }
}
.homework__detail__item__hd {
  font-size: 12px;
  margin-top: 5px;
  margin-bottom: 10px;
  font-weight: bold;
}
.homework__detail__item {
  margin-top: 15px;
  padding: 14px 20px;
  border-radius: 10px;
  background: #fafafa;
}
.homework__detail__item__bd {
  border-top: 1px solid #ececec;
  border-bottom: 1px solid #ececec;
  padding: 12px 0 20px;
  p {
    font-size: 14px;
  }
  ol {
    margin-left: 20px;
  }
}
.homework__detail__item__ft {
  margin-top: 10px;
  .question__options {
    padding: 0;
    margin: 0;
    margin-left: 20px;
  }
}
.homework__detail__item__score {
  float: right;
  font-size: 12px;
  span {
    display: inline-block;
    margin-left: 10px;
    width: 50px;
    height: 18px;
    line-height: 16px;
    border: 1px solid $mainColor;
    border-radius: 4px;
    text-align: center;
  }
}
.homework__detail__submit {
  display: block;
  width: 130px;
  margin-top: 30px;
  margin-left: auto;
  margin-right: auto;
}
</style>
<script>
import api from 'api/student/network'
export default {
  data () {
    return {
      info: {},
      list: []
    }
  },
  created () {
    this.getDetail().then(() => {
      this.getQuestion()
    })
  },
  methods: {
    submit () {
      this.$router.push('/student/homework/score')
    },
    getDetail () {
      return api.getDetail(this.$route.params.id).then((res) => {
        this.info = res.data.data
      })
    },
    getQuestion () {
      const ids = this.info.questions.map(item => item.quesstionId).join(',')
      return api.getQuestion(ids).then((res) => {
        this.list = res.data.data
      })
    }
  },
  filters: {
    type (val) {
      if (val === 'JUDGE') {
        return '判断'
      } else if (val === 'RADIO') {
        return '单选'
      } else if (val === 'CHECKBOX') {
        return '多选'
      }
    }
  }
}
</script>

